package com.bls.productmall.controller;

import com.bls.productmall.entity.User;
import com.bls.productmall.service.UserService;
import com.bls.productmall.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/*
* 用户接口类
* */
@RestController
@RequestMapping("/api/user")
@Slf4j
@CrossOrigin //开放前端的跨域访问
public class UserController {

    @Resource
    private UserService userService;

    // 获取用户列表
    @GetMapping("/list")
    public R getUserList(){
        List<User> list = userService.list();
        return R.ok().data("userList", list);
    }

    // 根据name查询user信息
    @GetMapping("/selectUserByName/{name}")
    public R selectUserByName(@PathVariable String name){
        log.info("selectUserByName根据name查询user信息...");
        return userService.selectUserByName(name);
    }

    // 用户登录接口
    @PostMapping("/login")
    public R login(@RequestBody User user){
        log.info("用户登录中...");
        return userService.login(user);
    }

    // 用户注册接口
    @PostMapping("/signIn")
    public R signIn(@RequestBody User user){
        log.info("用户注册中...");
        return userService.signIn(user);
    }
}



